#ifndef PROPPAGECTL_H_B8D9FEAC_D6EC_4E26_AFBD_B0787113574B
#define PROPPAGECTL_H_B8D9FEAC_D6EC_4E26_AFBD_B0787113574B
/**
 * \file ProppageCtl.h
 *
 * \brief Header file for class CPropPageCtl
 *
 * $Id: PropPageCtl.h,v 1.1.1.1 2008/04/23 13:29:14 mgh Exp $
 *
 *
 * Copyright (C) 2006 Michael G. Herstine <sp1ff@pobox.com>
 *
 * Permission to use, copy, or modify this source code is hereby granted
 * free of  charge, provided  that this copyright  notice appear  on all
 * copies  and  on   all  source  code  derived  from   this  code.   No
 * representation is made regarding the suitability of this software for
 * any  purpose.  It  is provided  "as  is" without  express or  implied
 * warranty.
 *
 *
 */

#ifndef DLGMIXIN_H_9C889376_DB3D_465B_8B7A_E4F0D0DAF90F
# include "DlgMixin.h"          // For base class CDlgMixin
#endif // not "DlgMixin.h"

#ifndef RESOURCE_H_INCLUDED
# include "Resource.h"          // Resource definitions
# define RESOURCE_H_INCLUDED
#endif // not "Resource.h"

/**
 * \class CPropPageCtl
 *
 * \brief Incarnates the CoPropPageCtl COM component
 *
 * \sa CDlgMixin, CConfigDlg
 *
 *
 * Some of the applications that may host this AddIn permit us to
 * integrate one or more property pages into their Tools | Options
 * property sheets.  This class implements a COM Composite Control
 * implementing the required interfaces for those hosts
 *
 * Note that we sublcass CDlgMixin to pick up implementation code common
 * to both this, our composite control, and CConfigDlg, our stand-alone
 * dialog implementation.
 *
 *
 */

class ATL_NO_VTABLE CPropPageCtl:
  public CComObjectRootEx<CComSingleThreadModel>,
  public CDlgMixin<CPropPageCtl>,
  public CComCompositeControl<CPropPageCtl>,
  public IPersistStreamInitImpl<CPropPageCtl>,
  public IOleControlImpl<CPropPageCtl>,
  public IOleObjectImpl<CPropPageCtl>,
  public IOleInPlaceActiveObjectImpl<CPropPageCtl>,
  public IViewObjectExImpl<CPropPageCtl>,
  public IOleInPlaceObjectWindowlessImpl<CPropPageCtl>,
  public IPersistStorageImpl<CPropPageCtl>,
  public ISpecifyPropertyPagesImpl<CPropPageCtl>,
  public IQuickActivateImpl<CPropPageCtl>,
  public IDataObjectImpl<CPropPageCtl>,
  public IProvideClassInfo2Impl<&CLSID_CoPropPageCtl,
                                NULL,
                                &LIBID_SampleCAILib>,
  public CComCoClass<CPropPageCtl, &CLSID_CoPropPageCtl>,
  public IDispatchImpl<EnvDTE::IDTToolsOptionsPage,
                       &__uuidof(EnvDTE::IDTToolsOptionsPage),
                       &EnvDTE::LIBID_EnvDTE,
                       7,
                       0>
{
public:
  /// Dialog resource ID, required by CComCompositeControl
  static const UINT IDD = IDD_PROPPAGE;

public:
  /// Default ctor required by ATL
  CPropPageCtl();
  /// Standard ATL initialization routine
  HRESULT FinalConstruct();
  /// Standard ATL cleanup routine
  void FinalRelease();
  /// Used by CDlgMixin
  std::string getHello() const
  { return m_strHello; }
  /// Used by CDlgMixin
  void setHello(const std::string &strHello)
  { m_strHello = strHello; }

# ifndef DOXYGEN_INVOKED        // Shield the macros from doxygen...
  /// Tell ATL about our Registrar scripts
  DECLARE_REGISTRY_RESOURCEID(IDR_PROPPAGE)
  /// Guard our reference count against child creation side-effects
  DECLARE_PROTECT_FINAL_CONSTRUCT()
  /// Tell ATL which interfaces we support
  BEGIN_COM_MAP(CPropPageCtl)
    COM_INTERFACE_ENTRY(IDTToolsOptionsPage)
    COM_INTERFACE_ENTRY(IViewObjectEx)
    COM_INTERFACE_ENTRY(IViewObject2)
    COM_INTERFACE_ENTRY(IViewObject)
    COM_INTERFACE_ENTRY(IOleInPlaceObjectWindowless)
    COM_INTERFACE_ENTRY(IOleInPlaceObject)
    COM_INTERFACE_ENTRY2(IOleWindow, IOleInPlaceObjectWindowless)
    COM_INTERFACE_ENTRY(IOleInPlaceActiveObject)
    COM_INTERFACE_ENTRY(IOleControl)
    COM_INTERFACE_ENTRY(IOleObject)
    COM_INTERFACE_ENTRY(IPersistStreamInit)
    COM_INTERFACE_ENTRY2(IPersist, IPersistStreamInit)
    COM_INTERFACE_ENTRY(ISpecifyPropertyPages)
    COM_INTERFACE_ENTRY(IQuickActivate)
    COM_INTERFACE_ENTRY(IPersistStorage)
    COM_INTERFACE_ENTRY(IDataObject)
    COM_INTERFACE_ENTRY(IProvideClassInfo)
    COM_INTERFACE_ENTRY(IProvideClassInfo2)
  END_COM_MAP()
  /// Tell ATL which properties we support
  BEGIN_PROP_MAP(CPropPageCtl)
    PROP_DATA_ENTRY("_cx", m_sizeExtent.cx, VT_UI4)
    PROP_DATA_ENTRY("_cy", m_sizeExtent.cy, VT_UI4)
    PROP_ENTRY("BackColor", DISPID_BACKCOLOR, CLSID_StockColorPage)
  END_PROP_MAP()
  /// ATL Windows Message Map
  BEGIN_MSG_MAP(CPropPageCtl)
    MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
    CHAIN_MSG_MAP(CComCompositeControl<CPropPageCtl>)
  END_MSG_MAP()
  /// Setup Event Sinks
  BEGIN_SINK_MAP(CPropPageCtl)
    // N.B. Make sure event handlers all have the __stdcall calling
    // convention
  END_SINK_MAP()
  DECLARE_OLEMISC_STATUS(OLEMISC_RECOMPOSEONRESIZE |
                         OLEMISC_CANTLINKINSIDE |
                         OLEMISC_INSIDEOUT |
                         OLEMISC_ACTIVATEWHENVISIBLE |
                         OLEMISC_SETCLIENTSITEFIRST)
  // IViewObjectEx
  DECLARE_VIEW_STATUS(VIEWSTATUS_SOLIDBKGND | VIEWSTATUS_OPAQUE)
# endif // not DOXYGEN_INVOKED

  //////////////////////////////////////////////////////////////////////
  // Interface IDTToolsOptionsPage
public:
  /// Occurs immediately after a custom Tools Options page is created
  /// for the first time
  STDMETHOD(OnAfterCreated)(/*[in]*/ EnvDTE::_DTE *pDTEObject);
  /// Returns an object containing all properties contained on the
  /// specified custom Tools Options page.
  STDMETHOD(GetProperties)(/*[in, out]*/ IDispatch **pProperties);
  /// IDOK handler
  STDMETHOD(OnOK)();
  /// IDCANCEL handler
  STDMETHOD(OnCancel)();
  /// IDHELP handler
  STDMETHOD(OnHelp)();

private:
  STDMETHOD(OnAmbientPropertyChange)(DISPID dispid);
  LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam,
                       BOOL& bHandled);

  friend class IQuickActivateImpl<CPropPageCtl>;

private:
  std::string m_strHello;
  OLE_COLOR m_clrBackColor;

};

OBJECT_ENTRY_AUTO(__uuidof(CoPropPageCtl), CPropPageCtl)


// Local Variables:
// fill-column: 72
// indent-tabs-mode: nil
// show-trailing-whitespace: t
// End:

#endif // PROPPAGECTL_H_B8D9FEAC_D6EC_4E26_AFBD_B0787113574B
